package 设计模式.singleton;

public class singleton1 {
    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance==instance2);
        System.out.println("instance的hashcode="+instance.hashCode());
        System.out.println("instance的hashcode2="+instance2.hashCode());

    }
}

class Singleton{
    private Singleton(){
    }

    //private final static Singleton singleton=new Singleton();
    private  static Singleton singleton;

    static {
        singleton=new Singleton();
    }
    public static Singleton getInstance(){
        return singleton;
    }
}
